home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Text Capture FKEY / Text Capture source.cpt / 1.FKEY main.c < prev    next >
C/C++ Source or Header  |  1992-06-12  |  2KB  |  101 lines

  1. #define        ALLOCATE_GLOBALS    1
  2. #include "defs.h"
  3.  
  4. #include <Traps.h>
  5. #include "patching.h"
  6. #include "Prefs.h"
  7. #include "Copy text.h"
  8. #include "FixPC.h"
  9.  
  10. #define        ToolScratch        0x09CE    // an 8-byte scratch area in low memory
  11.  
  12. void Select_rect( Rect *result );
  13.  
  14. #define        CAPSLOCK_KEY    0x39
  15. #define        CONTROL_KEY        0x3B
  16.  
  17. #define        MEM_RESOURCE    0x20
  18.  
  19. pascal void main( void )
  20. {
  21.     GrafPtr        save_port;
  22.     Ptr            my_p;
  23.     SignedByte    my_state;
  24.     OSErr        err;
  25.     ProcPtr        FKEY_p;
  26.     
  27.     asm {
  28.         bra.S    @afterheader
  29.         DC.W    0
  30.         DC.L    'FKEY'
  31.         DC.W    6
  32.         DC.W    0
  33.     @afterheader
  34.         movem.l    a0-a5/d0-d7, -(SP)    ; save registers
  35.         FIXPC                        ; StripAddress
  36.         LEA        main, A4    ; set up globals
  37.         move.L    A4, my_p
  38.     }
  39.  
  40.     front = FrontWindow();
  41.     if (front == NIL)
  42.         goto getout;
  43.     GetPort( &save_port );
  44.     SetPort( front );
  45.  
  46.     my_h = RecoverHandle(my_p);
  47.     if (MemError() != noErr)    DebugStr("\pRecoverHandle error code");
  48.     my_state = HGetState( my_h );
  49.     if (my_state & MEM_RESOURCE)    // Is this the FKEY...
  50.     {
  51.         if ( KeyIsDown( CAPSLOCK_KEY ) || KeyIsDown( CONTROL_KEY ) )
  52.         {
  53.             Get_prefs( p_leave_open, my_h );
  54.             Configure_dialog( );
  55.             CloseResFile( pref_resfile );
  56.         }
  57.         else
  58.         {
  59.             Get_prefs( p_read_only, my_h );
  60.             switch (copy_mode)
  61.             {
  62.                 case c_all:
  63.                     Copy_text = Copy_all_text;
  64.                     selected_rect = front->portRect;
  65.                     break;
  66.                 case c_window:
  67.                     Copy_text = Copy_window_text;
  68.                     selected_rect = front->portRect;
  69.                     break;
  70.                 case c_selected:
  71.                     Copy_text = Copy_selected_text;
  72.                     Select_rect( &selected_rect );
  73.                     GlobalToLocal( &topLeft(selected_rect) );
  74.                     GlobalToLocal( &botRight(selected_rect) );
  75.                     break;
  76.             }
  77.             if (!EmptyRect(&selected_rect))
  78.             {
  79.                 err = HandToHand( &my_h ); // clone this resource
  80.                 if (err == noErr)
  81.                 {
  82.                     HLock( my_h );
  83.                     FKEY_p = (ProcPtr) StripAddress( *my_h );
  84.                     (*(pascal void (*)(void))FKEY_p)();
  85.                 }
  86.             }
  87.         } // not configuring
  88.     }
  89.     else                            // ... or the copy?
  90.     {
  91.         InvalRect( &selected_rect );
  92.         PATCH( BeginUpDate );
  93.         PATCH( EndUpDate );
  94.     }
  95.  
  96.     SetPort( save_port );
  97. getout:
  98.     asm {
  99.         movem.l    (SP)+, a0-a5/d0-d7
  100.     }
  101. }